{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from vnpy.trader.optimize import OptimizationSetting\n",
    "from vnpy_ctastrategy.backtesting import BacktestingEngine\n",
    "from vnpy.trader.setting import SETTINGS\n",
    "import vnpy_tushare\n",
    "from datetime import datetime\n",
    "from vnpy_tushare.tushare_datafeed import TushareDatafeed\n",
    "from vnpy.trader.object import HistoryRequest\n",
    "from vnpy.trader.constant import Exchange, Interval"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 希望之星\n",
    "def is_morning_star(am):\n",
    "    if am.size < 3:\n",
    "        return False\n",
    "    first_close = am.close[-3]\n",
    "    first_open = am.open[-3]\n",
    "    second_close = am.close[-2]\n",
    "    second_open = am.open[-2]\n",
    "    third_close = am.close[-1]\n",
    "    third_open = am.open[-1]\n",
    "    is_first_bearish = first_close < first_open\n",
    "    is_second_small = abs(second_close - second_open) / second_open < 0.01\n",
    "    is_third_bullish = third_close > third_open\n",
    "    return is_first_bearish and is_second_small and is_third_bullish\n",
    "\n",
    "\n",
    "# 反攻\n",
    "def is_counter_attack(am):\n",
    "    if am.size < 2:\n",
    "        return False\n",
    "    first_close = am.close[-2]\n",
    "    first_open = am.open[-2]\n",
    "    second_close = am.close[-1]\n",
    "    second_open = am.open[-1]\n",
    "    is_first_bearish = first_close < first_open\n",
    "    is_second_bullish = second_close > second_open\n",
    "    is_close_to_first_open = abs(second_close - first_open) / first_open < 0.01\n",
    "    return is_first_bearish and is_second_bullish and is_close_to_first_open\n",
    "\n",
    "\n",
    " # 淡友反攻\n",
    "def is_dark_cloud_cover(am):\n",
    "    if am.size < 2:\n",
    "        return False\n",
    "    first_close = am.close[-2]\n",
    "    first_open = am.open[-2]\n",
    "    second_close = am.close[-1]\n",
    "    second_open = am.open[-1]\n",
    "    is_first_bullish = first_close > first_open\n",
    "    is_second_bearish = second_close < second_open\n",
    "    is_close_below_first_open = second_close < first_open\n",
    "    return is_first_bullish and is_second_bearish and is_close_below_first_open\n",
    "\n",
    "\n",
    "# 倾盆大雨\n",
    "def is_rainstorm(am):\n",
    "    if am.size < 2:\n",
    "        return False\n",
    "    first_close = am.close[-2]\n",
    "    first_open = am.open[-2]\n",
    "    second_close = am.close[-1]\n",
    "    second_open = am.open[-1]\n",
    "    is_first_bullish = first_close > first_open\n",
    "    is_second_bearish = second_close < second_open\n",
    "    is_close_below_first_open = second_close < first_open\n",
    "    return is_first_bullish and is_second_bearish and is_close_below_first_open\n",
    "\n",
    "\n",
    "# 曙光初现\n",
    "def is_piercing_pattern(am):\n",
    "    if am.size < 2:\n",
    "        return False\n",
    "    first_close = am.close[-2]\n",
    "    first_open = am.open[-2]\n",
    "    second_close = am.close[-1]\n",
    "    second_open = am.open[-1]\n",
    "    is_first_bearish = first_close < first_open\n",
    "    is_second_bullish = second_close > second_open\n",
    "    is_close_above_half = second_close > (first_open + first_close) / 2\n",
    "    return is_first_bearish and is_second_bullish and is_close_above_half\n",
    "\n",
    "\n",
    "# 旭日东升\n",
    "def is_bullish_engulfing(am):\n",
    "    if am.size < 2:\n",
    "        return False\n",
    "    first_close = am.close[-2]\n",
    "    first_open = am.open[-2]\n",
    "    second_close = am.close[-1]\n",
    "    second_open = am.open[-1]\n",
    "    is_first_bearish = first_close < first_open\n",
    "    is_second_bullish = second_close > second_open\n",
    "    is_engulfing = second_open < first_close and second_close > first_open\n",
    "    return is_first_bearish and is_second_bullish and is_engulfing\n",
    "\n",
    "\n",
    "# 平顶\n",
    "def is_flat_top(am, threshold=0.01):\n",
    "    if am.size < 2:\n",
    "        return False\n",
    "    highs = am.high[-2:]\n",
    "    max_high = max(highs)\n",
    "    min_high = min(highs)\n",
    "    return (max_high - min_high) / max_high < threshold\n",
    "\n",
    "\n",
    "# 塔顶\n",
    "def is_tower_top(am):\n",
    "    if am.size < 3:\n",
    "        return False\n",
    "    middle_high = am.high[-2]\n",
    "    left_high = am.high[-3]\n",
    "    right_high = am.high[-1]\n",
    "    return middle_high > left_high and middle_high > right_high\n",
    "\n",
    "\n",
    "# 平底\n",
    "def is_flat_bottom(am, threshold=0.01):\n",
    "    if am.size < 2:\n",
    "        return False\n",
    "    lows = am.low[-2:]\n",
    "    max_low = max(lows)\n",
    "    min_low = min(lows)\n",
    "    return (max_low - min_low) / max_low < threshold\n",
    "\n",
    "\n",
    "# 塔底\n",
    "def is_tower_bottom(am):\n",
    "    if am.size < 3:\n",
    "        return False\n",
    "    middle_low = am.low[-2]\n",
    "    left_low = am.low[-3]\n",
    "    right_low = am.low[-1]\n",
    "    return middle_low < left_low and middle_low < right_low\n",
    "\n",
    "\n",
    "# 双飞\n",
    "def is_two_crows(am):\n",
    "    if am.size < 3:\n",
    "        return False\n",
    "    first_close = am.close[-3]\n",
    "    first_open = am.open[-3]\n",
    "    second_close = am.close[-2]\n",
    "    second_open = am.open[-2]\n",
    "    third_close = am.close[-1]\n",
    "    third_open = am.open[-1]\n",
    "    is_first_bullish = first_close > first_open\n",
    "    is_second_bearish = second_close < second_open\n",
    "    is_third_bearish = third_close < third_open\n",
    "    is_third_lower = third_close < second_close\n",
    "    return is_first_bullish and is_second_bearish and is_third_bearish and is_third_lower\n",
    "\n",
    "\n",
    "# 低位盘旋\n",
    "def is_low_consolidation(am, threshold=0.01):\n",
    "    if am.size < 3:\n",
    "        return False\n",
    "    closes = am.close[-3:]\n",
    "    max_close = max(closes)\n",
    "    min_close = min(closes)\n",
    "    return (max_close - min_close) / max_close < threshold\n",
    "\n",
    "\n",
    "# 上升抵抗\n",
    "def is_rising_wedge(am):\n",
    "    if am.size < 3:\n",
    "        return False\n",
    "    highs = am.high[-3:]\n",
    "    return highs[0] < highs[1] < highs[2] and (highs[1] - highs[0]) > (highs[2] - highs[1])\n",
    "\n",
    "\n",
    "# 下探上涨\n",
    "def is_falling_wedge(am):\n",
    "    if am.size < 3:\n",
    "        return False\n",
    "    lows = am.low[-3:]\n",
    "    return lows[0] > lows[1] > lows[2] and (lows[0] - lows[1]) > (lows[1] - lows[2])\n",
    "\n",
    "\n",
    "# 黑三兵\n",
    "def is_three_black_crows(am):\n",
    "    if am.size < 3:\n",
    "        return False\n",
    "    first_close = am.close[-3]\n",
    "    first_open = am.open[-3]\n",
    "    second_close = am.close[-2]\n",
    "    second_open = am.open[-2]\n",
    "    third_close = am.close[-1]\n",
    "    third_open = am.open[-1]\n",
    "    is_first_bearish = first_close < first_open\n",
    "    is_second_bearish = second_close < second_open\n",
    "    is_third_bearish = third_close < third_open\n",
    "    is_descending = first_close > second_close > third_close\n",
    "    return is_first_bearish and is_second_bearish and is_third_bearish and is_descending\n",
    "\n",
    "\n",
    "# 下降抵抗\n",
    "def is_falling_resistance(am):\n",
    "    if am.size < 3:\n",
    "        return False\n",
    "    highs = am.high[-3:]\n",
    "    lows = am.low[-3:]\n",
    "    return highs[0] > highs[1] > highs[2] and lows[0] > lows[1] > lows[2]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [],
   "source": [
    "engine = BacktestingEngine()\n",
    "engine.set_parameters(\n",
    "    vt_symbol=\"000001.SZSE\",\n",
    "    interval=\"d\",\n",
    "    start=datetime(2024, 1, 1),\n",
    "    end=datetime(2024, 12, 30),\n",
    "    rate=0.3/10000,\n",
    "    slippage=0.2,\n",
    "    size=100,   # 每手数量\n",
    "    pricetick=0.1,\n",
    "    capital=1_000_000,    # 初始资金\n",
    ")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "SETTINGS['datafeed.username'] = \"token\"\n",
    "SETTINGS['datafeed.password'] = \"600713cc777ee2505142620a527eebe2c27a973b5fe89fce9fe8f07f\"\n",
    "\n",
    "tsengine = TushareDatafeed()\n",
    "req = HistoryRequest(engine.vt_symbol.split('.')[0], Exchange.SZSE, datetime(2024, 1, 1, 0, 0, 0), datetime(2024, 12, 31, 23, 59, 59), Interval.DAILY)\n",
    "data = tsengine.query_bar_history(req)\n",
    "engine.history_data.extend(data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "BarData(gateway_name='TS', extra=None, symbol='000001', exchange=<Exchange.SZSE: 'SZSE'>, datetime=datetime.datetime(2024, 1, 2, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='Asia/Shanghai')), interval=<Interval.DAILY: 'd'>, volume=1158366.45, turnover=1075742.252, open_interest=0, open_price=9.39, high_price=9.42, low_price=9.21, close_price=9.21)"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "表 kline_data_000001_SZSE 创建成功！\n",
      "数据插入成功！\n"
     ]
    }
   ],
   "source": [
    "import pymysql\n",
    "from datetime import datetime\n",
    "from zoneinfo import ZoneInfo\n",
    "\n",
    "# 数据库连接配置\n",
    "db_config = {\n",
    "    'host': 'localhost',  # 数据库地址\n",
    "    'user': 'root',       # 用户名\n",
    "    'password': '123456', # 密码\n",
    "    'database': 'tushare_db',  # 数据库名称\n",
    "    'charset': 'utf8mb4',      # 字符集\n",
    "}\n",
    "\n",
    "# 股票代码\n",
    "vt_symbol = engine.vt_symbol\n",
    "\n",
    "# 连接数据库\n",
    "try:\n",
    "    connection = pymysql.connect(**db_config)\n",
    "    cursor = connection.cursor()\n",
    "\n",
    "    # 动态生成表名\n",
    "    table_name = f\"kline_data_{vt_symbol.replace('.', '_')}\"  # 将 . 替换为 _\n",
    "\n",
    "    # 创建表的 SQL 语句\n",
    "    create_table_query = f\"\"\"\n",
    "    CREATE TABLE IF NOT EXISTS {table_name} (\n",
    "        id INT AUTO_INCREMENT PRIMARY KEY,\n",
    "        gateway_name VARCHAR(50),\n",
    "        symbol VARCHAR(20),\n",
    "        exchange VARCHAR(20),\n",
    "        datetime DATETIME,\n",
    "        time_interval VARCHAR(20),  -- 将 interval 改为 time_interval\n",
    "        volume FLOAT,\n",
    "        turnover FLOAT,\n",
    "        open_interest FLOAT,\n",
    "        open_price FLOAT,\n",
    "        high_price FLOAT,\n",
    "        low_price FLOAT,\n",
    "        close_price FLOAT\n",
    "    )\n",
    "    \"\"\"\n",
    "\n",
    "    # 执行创建表的 SQL\n",
    "    cursor.execute(create_table_query)\n",
    "    print(f\"表 {table_name} 创建成功！\")\n",
    "\n",
    "    # 插入数据的 SQL 语句\n",
    "    insert_query = f\"\"\"\n",
    "    INSERT INTO {table_name} (\n",
    "        gateway_name, symbol, exchange, datetime, time_interval,\n",
    "        volume, turnover, open_interest, open_price, high_price, low_price, close_price\n",
    "    ) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)\n",
    "    \"\"\"\n",
    "\n",
    "    # 遍历数据并插入到数据库\n",
    "    for bar in data:\n",
    "        # 将 datetime 转换为不带时区的字符串\n",
    "        dt_str = bar.datetime.strftime('%Y-%m-%d %H:%M:%S')\n",
    "\n",
    "        # 插入数据\n",
    "        cursor.execute(insert_query, (\n",
    "            bar.gateway_name,\n",
    "            bar.symbol,\n",
    "            bar.exchange.value,  # 获取枚举值\n",
    "            dt_str,\n",
    "            bar.interval.value,  # 获取枚举值\n",
    "            bar.volume,\n",
    "            bar.turnover,\n",
    "            bar.open_interest,\n",
    "            bar.open_price,\n",
    "            bar.high_price,\n",
    "            bar.low_price,\n",
    "            bar.close_price\n",
    "        ))\n",
    "\n",
    "    # 提交事务\n",
    "    connection.commit()\n",
    "    print(\"数据插入成功！\")\n",
    "\n",
    "except pymysql.Error as e:\n",
    "    print(f\"数据库操作失败: {e}\")\n",
    "\n",
    "finally:\n",
    "    # 关闭连接\n",
    "    if cursor:\n",
    "        cursor.close()\n",
    "    if connection:\n",
    "        connection.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "从表 kline_data_000001_SZSE 中读取了 484 条数据。\n"
     ]
    }
   ],
   "source": [
    "import pymysql\n",
    "from datetime import datetime\n",
    "from zoneinfo import ZoneInfo\n",
    "from vnpy.trader.constant import Exchange, Interval\n",
    "from vnpy.trader.object import BarData\n",
    "\n",
    "# 数据库连接配置\n",
    "db_config = {\n",
    "    'host': 'localhost',  # 数据库地址\n",
    "    'user': 'root',       # 用户名\n",
    "    'password': '123456', # 密码\n",
    "    'database': 'tushare_db',  # 数据库名称\n",
    "    'charset': 'utf8mb4',      # 字符集\n",
    "}\n",
    "\n",
    "# 股票代码\n",
    "vt_symbol = engine.vt_symbol\n",
    "\n",
    "# 动态生成表名\n",
    "table_name = f\"kline_data_{vt_symbol.replace('.', '_')}\"  # 将 . 替换为 _\n",
    "\n",
    "# 连接数据库\n",
    "try:\n",
    "    connection = pymysql.connect(**db_config)\n",
    "    cursor = connection.cursor()\n",
    "\n",
    "    # 查询数据的 SQL 语句\n",
    "    select_query = f\"\"\"\n",
    "    SELECT\n",
    "        gateway_name, symbol, exchange, datetime, time_interval,\n",
    "        volume, turnover, open_interest, open_price, high_price, low_price, close_price\n",
    "    FROM {table_name}\n",
    "    \"\"\"\n",
    "\n",
    "    # 执行查询\n",
    "    cursor.execute(select_query)\n",
    "    rows = cursor.fetchall()\n",
    "\n",
    "    # 将查询结果转换为 BarData 对象列表\n",
    "    data = []\n",
    "    for row in rows:\n",
    "        bar = BarData(\n",
    "            gateway_name=row[0],\n",
    "            symbol=row[1],\n",
    "            exchange=Exchange(row[2]),  # 将字符串转换为 Exchange 枚举\n",
    "            datetime=row[3].replace(tzinfo=ZoneInfo('Asia/Shanghai')),\n",
    "            interval=Interval(row[4]),  # 将字符串转换为 Interval 枚举\n",
    "            volume=row[5],\n",
    "            turnover=row[6],\n",
    "            open_interest=row[7],\n",
    "            open_price=row[8],\n",
    "            high_price=row[9],\n",
    "            low_price=row[10],\n",
    "            close_price=row[11]\n",
    "        )\n",
    "        data.append(bar)\n",
    "\n",
    "    print(f\"从表 {table_name} 中读取了 {len(data)} 条数据。\")\n",
    "\n",
    "except pymysql.Error as e:\n",
    "    print(f\"数据库操作失败: {e}\")\n",
    "\n",
    "finally:\n",
    "    # 关闭连接\n",
    "    if cursor:\n",
    "        cursor.close()\n",
    "    if connection:\n",
    "        connection.close()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "BarData(gateway_name='TS', extra=None, symbol='000001', exchange=<Exchange.SZSE: 'SZSE'>, datetime=datetime.datetime(2024, 1, 2, 0, 0, tzinfo=zoneinfo.ZoneInfo(key='Asia/Shanghai')), interval=<Interval.DAILY: 'd'>, volume=1158370.0, turnover=1075740.0, open_interest=0.0, open_price=9.39, high_price=9.42, low_price=9.21, close_price=9.21)"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data[0]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [],
   "source": [
    "from vnpy_ctastrategy import (\n",
    "    CtaTemplate,\n",
    "    StopOrder,\n",
    "    Direction,\n",
    "    TickData,\n",
    "    BarData,\n",
    "    TradeData,\n",
    "    OrderData,\n",
    "    BarGenerator,\n",
    "    ArrayManager,\n",
    ")\n",
    "\n",
    "class KLinePatternStrategy(CtaTemplate):\n",
    "    author = \"Youpeng Hu\"\n",
    "    fixed_size = 100  # 每次交易的数量\n",
    "\n",
    "    def __init__(self, cta_engine, strategy_name, vt_symbol, setting):\n",
    "        super().__init__(cta_engine, strategy_name, vt_symbol, setting)\n",
    "        self.bg = BarGenerator(self.on_bar)  # K线生成器\n",
    "        self.am = ArrayManager()  # K线数据管理器\n",
    "\n",
    "    def on_init(self):\n",
    "        \"\"\"策略初始化\"\"\"\n",
    "        self.write_log(\"策略初始化\")\n",
    "        self.load_bar(10)  # 加载历史数据\n",
    "\n",
    "    def on_start(self):\n",
    "        \"\"\"策略启动\"\"\"\n",
    "        self.write_log(\"策略启动\")\n",
    "\n",
    "    def on_stop(self):\n",
    "        \"\"\"策略停止\"\"\"\n",
    "        self.write_log(\"策略停止\")\n",
    "\n",
    "    def on_tick(self, tick: TickData):\n",
    "        \"\"\"Tick数据更新\"\"\"\n",
    "        self.bg.update_tick(tick)\n",
    "\n",
    "    def on_bar(self, bar: BarData):\n",
    "        \"\"\"K线数据更新\"\"\"\n",
    "        self.am.update_bar(bar)\n",
    "        if not self.am.inited:  # 确保有足够的数据\n",
    "            return\n",
    "        \n",
    "        # 获取当前账户资金\n",
    "        capital = self.cta_engine.capital  # 当前账户资金\n",
    "        price = bar.close_price  # 当前价格\n",
    "        size = self.fixed_size  # 默认手数\n",
    "\n",
    "        # 计算买入所需资金\n",
    "        required_capital = price * size * 100  # 假设1手=100股\n",
    "        if required_capital > capital:\n",
    "            # 如果余额不足，调整手数\n",
    "            size = int(capital / (price * 100))  # 按最大可用资金计算手数\n",
    "            if size == 0:\n",
    "                return  # 余额不足以买入1手，跳过交易\n",
    "            \n",
    "    # open_price, high_price, low_price, close_price\n",
    "    # self.buy(bar.open_price, self.fixed_size)\n",
    "    # self.sell(bar.open_price, self.fixed_size)\n",
    "\n",
    "        # 根据K线形态生成交易信号\n",
    "        if is_morning_star(self.am):  # 希望之星\n",
    "            self.buy(bar.close_price, self.fixed_size)  # 以当前K线的收盘价买入\n",
    "        elif is_counter_attack(self.am):  # 反攻\n",
    "            self.buy(bar.close_price, self.fixed_size)\n",
    "        elif is_dark_cloud_cover(self.am):  # 淡友反攻\n",
    "            self.sell(bar.close_price, self.fixed_size) # 以当前K线的收盘价卖出\n",
    "        elif is_rainstorm(self.am):  # 倾盆大雨\n",
    "            self.sell(bar.close_price, self.fixed_size)\n",
    "        elif is_piercing_pattern(self.am):  # 曙光初现\n",
    "            self.buy(bar.close_price, self.fixed_size)\n",
    "        elif is_bullish_engulfing(self.am):  # 旭日东升\n",
    "            self.buy(bar.close_price, self.fixed_size)\n",
    "        elif is_flat_top(self.am):  # 平顶\n",
    "            self.sell(bar.close_price, self.fixed_size)\n",
    "        elif is_tower_top(self.am):  # 塔顶\n",
    "            self.sell(bar.close_price, self.fixed_size)\n",
    "        elif is_flat_bottom(self.am):  # 平底\n",
    "            self.buy(bar.close_price, self.fixed_size)\n",
    "        elif is_tower_bottom(self.am):  # 塔底\n",
    "            self.buy(bar.close_price, self.fixed_size)\n",
    "        elif is_two_crows(self.am):  # 双飞\n",
    "            self.sell(bar.close_price, self.fixed_size)\n",
    "        elif is_low_consolidation(self.am):  # 低位盘旋\n",
    "            self.sell(bar.close_price, self.fixed_size)\n",
    "        elif is_rising_wedge(self.am):  # 上升抵抗形\n",
    "            self.buy(bar.close_price, self.fixed_size)\n",
    "        elif is_falling_wedge(self.am):  # 下探上涨形\n",
    "            self.buy(bar.close_price, self.fixed_size)\n",
    "        elif is_three_black_crows(self.am):  # 黑三兵\n",
    "            self.sell(bar.close_price, self.fixed_size)\n",
    "        elif is_falling_resistance(self.am):  # 下降抵抗\n",
    "            self.sell(bar.close_price, self.fixed_size)\n",
    "\n",
    "        self.put_event()  # 更新图形界面\n",
    "\n",
    "    def on_order(self, order: OrderData):\n",
    "        \"\"\"订单更新\"\"\"\n",
    "        pass\n",
    "\n",
    "    def on_trade(self, trade: TradeData):\n",
    "        \"\"\"成交更新\"\"\"\n",
    "        self.put_event()\n",
    "\n",
    "    def on_stop_order(self, stop_order: StopOrder):\n",
    "        \"\"\"停止单更新\"\"\"\n",
    "        pass"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Looking in indexes: https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple\n",
      "Requirement already satisfied: nbformat in f:\\software\\anacondaconfig\\envs\\vnpy\\lib\\site-packages (5.10.4)\n",
      "Requirement already satisfied: fastjsonschema>=2.15 in f:\\software\\anacondaconfig\\envs\\vnpy\\lib\\site-packages (from nbformat) (2.21.1)\n",
      "Requirement already satisfied: jsonschema>=2.6 in f:\\software\\anacondaconfig\\envs\\vnpy\\lib\\site-packages (from nbformat) (4.23.0)\n",
      "Requirement already satisfied: jupyter-core!=5.0.*,>=4.12 in f:\\software\\anacondaconfig\\envs\\vnpy\\lib\\site-packages (from nbformat) (5.7.2)\n",
      "Requirement already satisfied: traitlets>=5.1 in f:\\software\\anacondaconfig\\envs\\vnpy\\lib\\site-packages (from nbformat) (5.14.3)\n",
      "Requirement already satisfied: attrs>=22.2.0 in f:\\software\\anacondaconfig\\envs\\vnpy\\lib\\site-packages (from jsonschema>=2.6->nbformat) (25.1.0)\n",
      "Requirement already satisfied: jsonschema-specifications>=2023.03.6 in f:\\software\\anacondaconfig\\envs\\vnpy\\lib\\site-packages (from jsonschema>=2.6->nbformat) (2024.10.1)\n",
      "Requirement already satisfied: referencing>=0.28.4 in f:\\software\\anacondaconfig\\envs\\vnpy\\lib\\site-packages (from jsonschema>=2.6->nbformat) (0.36.2)\n",
      "Requirement already satisfied: rpds-py>=0.7.1 in f:\\software\\anacondaconfig\\envs\\vnpy\\lib\\site-packages (from jsonschema>=2.6->nbformat) (0.23.1)\n",
      "Requirement already satisfied: platformdirs>=2.5 in f:\\software\\anacondaconfig\\envs\\vnpy\\lib\\site-packages (from jupyter-core!=5.0.*,>=4.12->nbformat) (4.3.6)\n",
      "Requirement already satisfied: pywin32>=300 in f:\\software\\anacondaconfig\\envs\\vnpy\\lib\\site-packages (from jupyter-core!=5.0.*,>=4.12->nbformat) (308)\n",
      "Requirement already satisfied: typing-extensions>=4.4.0 in f:\\software\\anacondaconfig\\envs\\vnpy\\lib\\site-packages (from referencing>=0.28.4->jsonschema>=2.6->nbformat) (4.12.2)\n"
     ]
    }
   ],
   "source": [
    "!pip install nbformat"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2025-03-02 10:23:00.493533\t策略初始化完成\n",
      "2025-03-02 10:23:00.493533\t开始回放历史数据\n",
      "2025-03-02 10:23:00.493533\t回放进度：= [0%]\n",
      "2025-03-02 10:23:00.494538\t回放进度：== [10%]\n",
      "2025-03-02 10:23:00.494538\t回放进度：=== [20%]\n",
      "2025-03-02 10:23:00.494538\t回放进度：==== [30%]\n",
      "2025-03-02 10:23:00.495534\t回放进度：===== [40%]\n",
      "2025-03-02 10:23:00.495534\t回放进度：====== [50%]\n",
      "2025-03-02 10:23:00.496548\t回放进度：======= [60%]\n",
      "2025-03-02 10:23:00.497546\t回放进度：======== [70%]\n",
      "2025-03-02 10:23:00.497546\t回放进度：========= [80%]\n",
      "2025-03-02 10:23:00.498533\t回放进度：========== [90%]\n",
      "2025-03-02 10:23:00.498533\t回放进度：=========== [100%]\n",
      "2025-03-02 10:23:00.498533\t历史数据回放结束\n",
      "2025-03-02 10:23:00.498533\t开始计算逐日盯市盈亏\n",
      "2025-03-02 10:23:00.500533\t逐日盯市盈亏计算完成\n",
      "2025-03-02 10:23:00.500533\t开始计算策略统计指标\n",
      "2025-03-02 10:23:00.505543\t------------------------------\n",
      "2025-03-02 10:23:00.505543\t首个交易日：\t2024-01-02\n",
      "2025-03-02 10:23:00.505543\t最后交易日：\t2024-12-31\n",
      "2025-03-02 10:23:00.505543\t总交易日：\t242\n",
      "2025-03-02 10:23:00.505543\t盈利交易日：\t59\n",
      "2025-03-02 10:23:00.505543\t亏损交易日：\t81\n",
      "2025-03-02 10:23:00.505543\t起始资金：\t1,000,000.00\n",
      "2025-03-02 10:23:00.505543\t结束资金：\t404,664.70\n",
      "2025-03-02 10:23:00.505543\t总收益率：\t-59.53%\n",
      "2025-03-02 10:23:00.505543\t年化收益：\t-59.04%\n",
      "2025-03-02 10:23:00.505543\t最大回撤: \t-737,232.67\n",
      "2025-03-02 10:23:00.505543\t百分比最大回撤: -73.72%\n",
      "2025-03-02 10:23:00.505543\t最大回撤天数: \t280\n",
      "2025-03-02 10:23:00.505543\t总盈亏：\t-595,335.30\n",
      "2025-03-02 10:23:00.505543\t总手续费：\t435.30\n",
      "2025-03-02 10:23:00.505543\t总滑点：\t268,000.00\n",
      "2025-03-02 10:23:00.505543\t总成交金额：\t14,510,100.00\n",
      "2025-03-02 10:23:00.505543\t总成交笔数：\t134\n",
      "2025-03-02 10:23:00.505543\t日均盈亏：\t-2,460.06\n",
      "2025-03-02 10:23:00.505543\t日均手续费：\t1.80\n",
      "2025-03-02 10:23:00.505543\t日均滑点：\t1,107.44\n",
      "2025-03-02 10:23:00.505543\t日均成交金额：\t59,959.09\n",
      "2025-03-02 10:23:00.505543\t日均成交笔数：\t0.5537190082644629\n",
      "2025-03-02 10:23:00.505543\t日均收益率：\t-0.37%\n",
      "2025-03-02 10:23:00.505543\t收益标准差：\t7.32%\n",
      "2025-03-02 10:23:00.505543\tSharpe Ratio：\t-0.79\n",
      "2025-03-02 10:23:00.505543\tEWM Sharpe：\t-0.90\n",
      "2025-03-02 10:23:00.505543\t收益回撤比：\t-0.81\n",
      "2025-03-02 10:23:00.506542\t策略统计指标计算完成\n"
     ]
    },
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "f:\\Software\\anacondaconfig\\envs\\vnpy\\lib\\site-packages\\vnpy_ctastrategy\\backtesting.py:400: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]`\n",
      "  ewm_sharpe: float = ((ewm_mean - daily_risk_free) / ewm_std)[-1] * np.sqrt(self.annual_days)\n"
     ]
    },
    {
     "data": {
      "application/vnd.plotly.v1+json": {
       "config": {
        "plotlyServerURL": "https://plot.ly"
       },
       "data": [
        {
         "mode": "lines",
         "name": "Balance",
         "type": "scatter",
         "x": [
          "2024-01-02",
          "2024-01-03",
          "2024-01-04",
          "2024-01-05",
          "2024-01-08",
          "2024-01-09",
          "2024-01-10",
          "2024-01-11",
          "2024-01-12",
          "2024-01-15",
          "2024-01-16",
          "2024-01-17",
          "2024-01-18",
          "2024-01-19",
          "2024-01-22",
          "2024-01-23",
          "2024-01-24",
          "2024-01-25",
          "2024-01-26",
          "2024-01-29",
          "2024-01-30",
          "2024-01-31",
          "2024-02-01",
          "2024-02-02",
          "2024-02-05",
          "2024-02-06",
          "2024-02-07",
          "2024-02-08",
          "2024-02-19",
          "2024-02-20",
          "2024-02-21",
          "2024-02-22",
          "2024-02-23",
          "2024-02-26",
          "2024-02-27",
          "2024-02-28",
          "2024-02-29",
          "2024-03-01",
          "2024-03-04",
          "2024-03-05",
          "2024-03-06",
          "2024-03-07",
          "2024-03-08",
          "2024-03-11",
          "2024-03-12",
          "2024-03-13",
          "2024-03-14",
          "2024-03-15",
          "2024-03-18",
          "2024-03-19",
          "2024-03-20",
          "2024-03-21",
          "2024-03-22",
          "2024-03-25",
          "2024-03-26",
          "2024-03-27",
          "2024-03-28",
          "2024-03-29",
          "2024-04-01",
          "2024-04-02",
          "2024-04-03",
          "2024-04-08",
          "2024-04-09",
          "2024-04-10",
          "2024-04-11",
          "2024-04-12",
          "2024-04-15",
          "2024-04-16",
          "2024-04-17",
          "2024-04-18",
          "2024-04-19",
          "2024-04-22",
          "2024-04-23",
          "2024-04-24",
          "2024-04-25",
          "2024-04-26",
          "2024-04-29",
          "2024-04-30",
          "2024-05-06",
          "2024-05-07",
          "2024-05-08",
          "2024-05-09",
          "2024-05-10",
          "2024-05-13",
          "2024-05-14",
          "2024-05-15",
          "2024-05-16",
          "2024-05-17",
          "2024-05-20",
          "2024-05-21",
          "2024-05-22",
          "2024-05-23",
          "2024-05-24",
          "2024-05-27",
          "2024-05-28",
          "2024-05-29",
          "2024-05-30",
          "2024-05-31",
          "2024-06-03",
          "2024-06-04",
          "2024-06-05",
          "2024-06-06",
          "2024-06-07",
          "2024-06-11",
          "2024-06-12",
          "2024-06-13",
          "2024-06-14",
          "2024-06-17",
          "2024-06-18",
          "2024-06-19",
          "2024-06-20",
          "2024-06-21",
          "2024-06-24",
          "2024-06-25",
          "2024-06-26",
          "2024-06-27",
          "2024-06-28",
          "2024-07-01",
          "2024-07-02",
          "2024-07-03",
          "2024-07-04",
          "2024-07-05",
          "2024-07-08",
          "2024-07-09",
          "2024-07-10",
          "2024-07-11",
          "2024-07-12",
          "2024-07-15",
          "2024-07-16",
          "2024-07-17",
          "2024-07-18",
          "2024-07-19",
          "2024-07-22",
          "2024-07-23",
          "2024-07-24",
          "2024-07-25",
          "2024-07-26",
          "2024-07-29",
          "2024-07-30",
          "2024-07-31",
          "2024-08-01",
          "2024-08-02",
          "2024-08-05",
          "2024-08-06",
          "2024-08-07",
          "2024-08-08",
          "2024-08-09",
          "2024-08-12",
          "2024-08-13",
          "2024-08-14",
          "2024-08-15",
          "2024-08-16",
          "2024-08-19",
          "2024-08-20",
          "2024-08-21",
          "2024-08-22",
          "2024-08-23",
          "2024-08-26",
          "2024-08-27",
          "2024-08-28",
          "2024-08-29",
          "2024-08-30",
          "2024-09-02",
          "2024-09-03",
          "2024-09-04",
          "2024-09-05",
          "2024-09-06",
          "2024-09-09",
          "2024-09-10",
          "2024-09-11",
          "2024-09-12",
          "2024-09-13",
          "2024-09-18",
          "2024-09-19",
          "2024-09-20",
          "2024-09-23",
          "2024-09-24",
          "2024-09-25",
          "2024-09-26",
          "2024-09-27",
          "2024-09-30",
          "2024-10-08",
          "2024-10-09",
          "2024-10-10",
          "2024-10-11",
          "2024-10-14",
          "2024-10-15",
          "2024-10-16",
          "2024-10-17",
          "2024-10-18",
          "2024-10-21",
          "2024-10-22",
          "2024-10-23",
          "2024-10-24",
          "2024-10-25",
          "2024-10-28",
          "2024-10-29",
          "2024-10-30",
          "2024-10-31",
          "2024-11-01",
          "2024-11-04",
          "2024-11-05",
          "2024-11-06",
          "2024-11-07",
          "2024-11-08",
          "2024-11-11",
          "2024-11-12",
          "2024-11-13",
          "2024-11-14",
          "2024-11-15",
          "2024-11-18",
          "2024-11-19",
          "2024-11-20",
          "2024-11-21",
          "2024-11-22",
          "2024-11-25",
          "2024-11-26",
          "2024-11-27",
          "2024-11-28",
          "2024-11-29",
          "2024-12-02",
          "2024-12-03",
          "2024-12-04",
          "2024-12-05",
          "2024-12-06",
          "2024-12-09",
          "2024-12-10",
          "2024-12-11",
          "2024-12-12",
          "2024-12-13",
          "2024-12-16",
          "2024-12-17",
          "2024-12-18",
          "2024-12-19",
          "2024-12-20",
          "2024-12-23",
          "2024-12-24",
          "2024-12-25",
          "2024-12-26",
          "2024-12-27",
          "2024-12-30",
          "2024-12-31"
         ],
         "xaxis": "x",
         "y": [
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          1000000,
          996696.7,
          994993.43,
          992290.154,
          990386.86,
          988583.59,
          986480.323,
          986480.323,
          986480.323,
          984777.29,
          980071.2,
          979968.152,
          979465.137,
          978262.137,
          973159.14,
          971356.122,
          968053.092,
          964950.0619999999,
          953447.002,
          948943.882,
          951440.7619999999,
          952337.672,
          969737.6719999999,
          970834.672,
          961034.6719999999,
          954831.651,
          954228.5879999999,
          935622.4619999999,
          932119.372,
          932816.2729999999,
          920813.183,
          918110.0689999999,
          919606.9550000001,
          930806.955,
          933503.88,
          936700.8199999998,
          938997.784,
          944294.754,
          931791.748,
          933488.7179999999,
          906985.688,
          905182.613,
          920782.6129999999,
          930179.5799999998,
          943473.5889999999,
          941670.6039999999,
          938667.634,
          925667.6340000001,
          927664.634,
          933561.628,
          937461.6279999999,
          917052.682,
          903052.6819999998,
          878749.5920000001,
          867643.3759999999,
          865943.3759999999,
          859040.2559999998,
          840137.1359999998,
          834433.9859999998,
          845130.8359999999,
          864927.7129999999,
          908724.6199999996,
          899321.5869999998,
          907315.521,
          911009.4879999999,
          923006.458,
          909103.4489999998,
          904900.4309999999,
          953797.416,
          940394.4579999998,
          993591.4939999997,
          970888.5989999998,
          978085.689,
          960182.7729999999,
          949179.8359999998,
          928376.8959999998,
          895573.9260000001,
          822973.926,
          794373.9259999999,
          645870.6859999998,
          583967.3259999999,
          410167.32599999977,
          262767.32599999977,
          526767.326,
          455963.8159999999,
          510960.21599999984,
          442556.6220000001,
          467753.0399999999,
          428949.46999999986,
          451045.84900000016,
          428842.2490000002,
          478438.6669999999,
          480935.1270000002,
          462431.5810000001,
          486228.038,
          495428.0379999998,
          511528.0379999999,
          532921.0420000001,
          584914.1719999999,
          567410.7729999998,
          552907.3589999999,
          544003.9389999998,
          494900.4889999998,
          517397.0089999997,
          422789.9889999998,
          468386.41899999965,
          498386.4189999999,
          511579.429,
          491775.97899999993,
          507472.502,
          531069.0519999999,
          447265.56299999985,
          463462.03799999994,
          472458.5279999997,
          483855.0479999999,
          565651.568,
          591848.178,
          565544.824,
          532641.4519999998,
          543138.0349999999,
          531034.6239999996,
          526431.2069999997,
          498527.7869999998,
          504724.3369999996,
          508720.887,
          442917.45499999984,
          438413.9659999999,
          403910.3960000002,
          421310.39599999983,
          383306.8770000001,
          466003.33999999985,
          461399.85999999987,
          470996.3890000001,
          433492.9149999998,
          449489.43799999997,
          438585.9580000001,
          402682.4659999998,
          362382.46600000013,
          341578.89599999995,
          360778.89600000007,
          368371.8159999999,
          326468.2760000002,
          404664.69700000016
         ],
         "yaxis": "y"
        },
        {
         "fill": "tozeroy",
         "fillcolor": "red",
         "mode": "lines",
         "name": "Drawdown",
         "type": "scatter",
         "x": [
          "2024-01-02",
          "2024-01-03",
          "2024-01-04",
          "2024-01-05",
          "2024-01-08",
          "2024-01-09",
          "2024-01-10",
          "2024-01-11",
          "2024-01-12",
          "2024-01-15",
          "2024-01-16",
          "2024-01-17",
          "2024-01-18",
          "2024-01-19",
          "2024-01-22",
          "2024-01-23",
          "2024-01-24",
          "2024-01-25",
          "2024-01-26",
          "2024-01-29",
          "2024-01-30",
          "2024-01-31",
          "2024-02-01",
          "2024-02-02",
          "2024-02-05",
          "2024-02-06",
          "2024-02-07",
          "2024-02-08",
          "2024-02-19",
          "2024-02-20",
          "2024-02-21",
          "2024-02-22",
          "2024-02-23",
          "2024-02-26",
          "2024-02-27",
          "2024-02-28",
          "2024-02-29",
          "2024-03-01",
          "2024-03-04",
          "2024-03-05",
          "2024-03-06",
          "2024-03-07",
          "2024-03-08",
          "2024-03-11",
          "2024-03-12",
          "2024-03-13",
          "2024-03-14",
          "2024-03-15",
          "2024-03-18",
          "2024-03-19",
          "2024-03-20",
          "2024-03-21",
          "2024-03-22",
          "2024-03-25",
          "2024-03-26",
          "2024-03-27",
          "2024-03-28",
          "2024-03-29",
          "2024-04-01",
          "2024-04-02",
          "2024-04-03",
          "2024-04-08",
          "2024-04-09",
          "2024-04-10",
          "2024-04-11",
          "2024-04-12",
          "2024-04-15",
          "2024-04-16",
          "2024-04-17",
          "2024-04-18",
          "2024-04-19",
          "2024-04-22",
          "2024-04-23",
          "2024-04-24",
          "2024-04-25",
          "2024-04-26",
          "2024-04-29",
          "2024-04-30",
          "2024-05-06",
          "2024-05-07",
          "2024-05-08",
          "2024-05-09",
          "2024-05-10",
          "2024-05-13",
          "2024-05-14",
          "2024-05-15",
          "2024-05-16",
          "2024-05-17",
          "2024-05-20",
          "2024-05-21",
          "2024-05-22",
          "2024-05-23",
          "2024-05-24",
          "2024-05-27",
          "2024-05-28",
          "2024-05-29",
          "2024-05-30",
          "2024-05-31",
          "2024-06-03",
          "2024-06-04",
          "2024-06-05",
          "2024-06-06",
          "2024-06-07",
          "2024-06-11",
          "2024-06-12",
          "2024-06-13",
          "2024-06-14",
          "2024-06-17",
          "2024-06-18",
          "2024-06-19",
          "2024-06-20",
          "2024-06-21",
          "2024-06-24",
          "2024-06-25",
          "2024-06-26",
          "2024-06-27",
          "2024-06-28",
          "2024-07-01",
          "2024-07-02",
          "2024-07-03",
          "2024-07-04",
          "2024-07-05",
          "2024-07-08",
          "2024-07-09",
          "2024-07-10",
          "2024-07-11",
          "2024-07-12",
          "2024-07-15",
          "2024-07-16",
          "2024-07-17",
          "2024-07-18",
          "2024-07-19",
          "2024-07-22",
          "2024-07-23",
          "2024-07-24",
          "2024-07-25",
          "2024-07-26",
          "2024-07-29",
          "2024-07-30",
          "2024-07-31",
          "2024-08-01",
          "2024-08-02",
          "2024-08-05",
          "2024-08-06",
          "2024-08-07",
          "2024-08-08",
          "2024-08-09",
          "2024-08-12",
          "2024-08-13",
          "2024-08-14",
          "2024-08-15",
          "2024-08-16",
          "2024-08-19",
          "2024-08-20",
          "2024-08-21",
          "2024-08-22",
          "2024-08-23",
          "2024-08-26",
          "2024-08-27",
          "2024-08-28",
          "2024-08-29",
          "2024-08-30",
          "2024-09-02",
          "2024-09-03",
          "2024-09-04",
          "2024-09-05",
          "2024-09-06",
          "2024-09-09",
          "2024-09-10",
          "2024-09-11",
          "2024-09-12",
          "2024-09-13",
          "2024-09-18",
          "2024-09-19",
          "2024-09-20",
          "2024-09-23",
          "2024-09-24",
          "2024-09-25",
          "2024-09-26",
          "2024-09-27",
          "2024-09-30",
          "2024-10-08",
          "2024-10-09",
          "2024-10-10",
          "2024-10-11",
          "2024-10-14",
          "2024-10-15",
          "2024-10-16",
          "2024-10-17",
          "2024-10-18",
          "2024-10-21",
          "2024-10-22",
          "2024-10-23",
          "2024-10-24",
          "2024-10-25",
          "2024-10-28",
          "2024-10-29",
          "2024-10-30",
          "2024-10-31",
          "2024-11-01",
          "2024-11-04",
          "2024-11-05",
          "2024-11-06",
          "2024-11-07",
          "2024-11-08",
          "2024-11-11",
          "2024-11-12",
          "2024-11-13",
          "2024-11-14",
          "2024-11-15",
          "2024-11-18",
          "2024-11-19",
          "2024-11-20",
          "2024-11-21",
          "2024-11-22",
          "2024-11-25",
          "2024-11-26",
          "2024-11-27",
          "2024-11-28",
          "2024-11-29",
          "2024-12-02",
          "2024-12-03",
          "2024-12-04",
          "2024-12-05",
          "2024-12-06",
          "2024-12-09",
          "2024-12-10",
          "2024-12-11",
          "2024-12-12",
          "2024-12-13",
          "2024-12-16",
          "2024-12-17",
          "2024-12-18",
          "2024-12-19",
          "2024-12-20",
          "2024-12-23",
          "2024-12-24",
          "2024-12-25",
          "2024-12-26",
          "2024-12-27",
          "2024-12-30",
          "2024-12-31"
         ],
         "xaxis": "x2",
         "y": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          -3303.3000000000466,
          -5006.569999999949,
          -7709.84600000002,
          -9613.140000000014,
          -11416.410000000033,
          -13519.677000000025,
          -13519.677000000025,
          -13519.677000000025,
          -15222.709999999963,
          -19928.800000000047,
          -20031.847999999998,
          -20534.863000000012,
          -21737.863000000012,
          -26840.859999999986,
          -28643.878000000026,
          -31946.908000000054,
          -35049.93800000008,
          -46552.99800000002,
          -51056.11800000002,
          -48559.23800000013,
          -47662.32799999998,
          -30262.328000000096,
          -29165.32799999998,
          -38965.328000000096,
          -45168.349000000046,
          -45771.41200000013,
          -64377.53800000006,
          -67880.62800000003,
          -67183.72700000007,
          -79186.81700000004,
          -81889.9310000001,
          -80393.04499999993,
          -69193.04500000004,
          -66496.12,
          -63299.18000000017,
          -61002.216000000015,
          -55705.24600000004,
          -68208.25199999998,
          -66511.28200000012,
          -93014.31200000003,
          -94817.38699999999,
          -79217.3870000001,
          -69820.42000000016,
          -56526.41100000008,
          -58329.396000000066,
          -61332.36600000004,
          -74332.36599999992,
          -72335.36600000004,
          -66438.37199999997,
          -62538.37200000009,
          -82947.31799999997,
          -96947.3180000002,
          -121250.40799999994,
          -132356.62400000007,
          -134056.62400000007,
          -140959.74400000018,
          -159862.86400000018,
          -165566.0140000002,
          -154869.1640000001,
          -135072.28700000013,
          -91275.38000000035,
          -100678.41300000018,
          -92684.47900000005,
          -88990.5120000001,
          -76993.54200000002,
          -90896.55100000021,
          -95099.56900000013,
          -46202.58400000003,
          -59605.54200000025,
          -6408.506000000285,
          -29111.401000000187,
          -21914.310999999987,
          -39817.22700000007,
          -50820.16400000022,
          -71623.10400000017,
          -104426.0739999999,
          -177026.07400000002,
          -205626.07400000014,
          -354129.31400000025,
          -416032.6740000001,
          -589832.6740000002,
          -737232.6740000002,
          -473232.674,
          -544036.1840000001,
          -489039.78400000016,
          -557443.3779999999,
          -532246.9600000001,
          -571050.5300000001,
          -548954.1509999998,
          -571157.7509999998,
          -521561.3330000001,
          -519064.8729999998,
          -537568.4189999999,
          -513771.962,
          -504571.9620000002,
          -488471.9620000001,
          -467078.95799999987,
          -415085.8280000001,
          -432589.2270000002,
          -447092.64100000006,
          -455996.0610000002,
          -505099.5110000002,
          -482602.9910000003,
          -577210.0110000002,
          -531613.5810000004,
          -501613.5810000001,
          -488420.571,
          -508224.02100000007,
          -492527.498,
          -468930.9480000001,
          -552734.4370000002,
          -536537.962,
          -527541.4720000003,
          -516144.9520000001,
          -434348.43200000003,
          -408151.82200000004,
          -434455.176,
          -467358.5480000002,
          -456861.9650000001,
          -468965.3760000004,
          -473568.7930000003,
          -501472.2130000002,
          -495275.6630000004,
          -491279.113,
          -557082.5450000002,
          -561586.0340000001,
          -596089.6039999998,
          -578689.6040000002,
          -616693.1229999999,
          -533996.6600000001,
          -538600.1400000001,
          -529003.6109999999,
          -566507.0850000002,
          -550510.562,
          -561414.0419999999,
          -597317.5340000002,
          -637617.5339999999,
          -658421.104,
          -639221.1039999999,
          -631628.1840000001,
          -673531.7239999998,
          -595335.3029999998
         ],
         "yaxis": "y2"
        },
        {
         "name": "Daily Pnl",
         "type": "bar",
         "xaxis": "x3",
         "y": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          -3303.3000000000075,
          -1703.2699999999886,
          -2703.2760000000026,
          -1903.2940000000021,
          -1803.2700000000043,
          -2103.266999999998,
          0,
          0,
          -1703.0330000000063,
          -4706.090000000021,
          -103.04800000000478,
          -503.0149999999787,
          -1203.000000000017,
          -5102.996999999987,
          -1803.0180000000043,
          -3303.030000000025,
          -3103.0299999999943,
          -11503.059999999974,
          -4503.120000000035,
          2496.879999999993,
          896.9100000000444,
          17399.99999999995,
          1097.0000000000582,
          -9800.00000000004,
          -6203.021000000017,
          -603.0630000000122,
          -18606.12599999999,
          -3503.089999999968,
          696.9009999999425,
          -12003.089999999966,
          -2703.113999999985,
          1496.8860000000677,
          11199.999999999904,
          2696.92500000006,
          3196.9399999998896,
          2296.9640000000854,
          5296.970000000057,
          -12503.006000000007,
          1696.9699999999207,
          -26503.02999999994,
          -1803.0750000000044,
          15599.99999999988,
          9396.966999999971,
          13294.00900000013,
          -1802.9850000000042,
          -3002.969999999979,
          -12999.999999999955,
          1996.9999999999145,
          5896.994000000062,
          3899.999999999917,
          -20408.945999999924,
          -14000.000000000198,
          -24303.08999999976,
          -11106.216000000099,
          -1699.9999999999638,
          -6903.120000000197,
          -18903.119999999977,
          -5703.149999999921,
          10696.850000000104,
          19796.876999999928,
          43796.90699999984,
          -9403.032999999861,
          7993.93400000017,
          3693.966999999853,
          11996.970000000107,
          -13903.009000000173,
          -4203.017999999953,
          48896.985000000095,
          -13402.958000000166,
          53197.03599999999,
          -22702.894999999968,
          7197.090000000213,
          -17902.91600000005,
          -11002.9370000002,
          -20802.93999999997,
          -32802.96999999974,
          -72600.00000000001,
          -28600.00000000017,
          -148503.24000000005,
          -61903.35999999989,
          -173800.0000000002,
          -147399.99999999997,
          264000.00000000023,
          -70803.51000000017,
          54996.399999999965,
          -68403.59399999975,
          25196.417999999827,
          -38803.570000000036,
          22096.37900000027,
          -22203.59999999996,
          49596.4179999997,
          2496.460000000313,
          -18503.546000000057,
          23796.456999999857,
          9199.999999999804,
          16100.000000000065,
          21393.00400000033,
          51993.12999999971,
          -17503.399000000132,
          -14503.413999999733,
          -8903.420000000278,
          -49103.44999999988,
          22496.519999999924,
          -94607.01999999987,
          45596.42999999987,
          30000.00000000025,
          13193.01000000013,
          -19803.450000000084,
          15696.523000000067,
          23596.549999999916,
          -83803.48900000012,
          16196.475000000071,
          8996.489999999765,
          11396.520000000195,
          81796.52000000014,
          26196.609999999913,
          -26303.35399999996,
          -32903.372000000265,
          10496.583000000179,
          -12103.411000000247,
          -4603.416999999945,
          -27903.41999999991,
          6196.549999999825,
          3996.5500000003694,
          -65803.43200000019,
          -4503.488999999947,
          -34503.569999999774,
          17399.99999999963,
          -38003.51899999977,
          82696.46299999977,
          -4603.479999999945,
          9596.529000000268,
          -37503.47400000029,
          15996.52300000015,
          -10903.47999999981,
          -35903.49200000036,
          -40299.999999999694,
          -20803.57000000015,
          19200.00000000016,
          7592.919999999807,
          -41903.53999999974,
          78196.421
         ],
         "yaxis": "y3"
        },
        {
         "name": "Days",
         "nbinsx": 100,
         "type": "histogram",
         "x": [
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          0,
          -3303.3000000000075,
          -1703.2699999999886,
          -2703.2760000000026,
          -1903.2940000000021,
          -1803.2700000000043,
          -2103.266999999998,
          0,
          0,
          -1703.0330000000063,
          -4706.090000000021,
          -103.04800000000478,
          -503.0149999999787,
          -1203.000000000017,
          -5102.996999999987,
          -1803.0180000000043,
          -3303.030000000025,
          -3103.0299999999943,
          -11503.059999999974,
          -4503.120000000035,
          2496.879999999993,
          896.9100000000444,
          17399.99999999995,
          1097.0000000000582,
          -9800.00000000004,
          -6203.021000000017,
          -603.0630000000122,
          -18606.12599999999,
          -3503.089999999968,
          696.9009999999425,
          -12003.089999999966,
          -2703.113999999985,
          1496.8860000000677,
          11199.999999999904,
          2696.92500000006,
          3196.9399999998896,
          2296.9640000000854,
          5296.970000000057,
          -12503.006000000007,
          1696.9699999999207,
          -26503.02999999994,
          -1803.0750000000044,
          15599.99999999988,
          9396.966999999971,
          13294.00900000013,
          -1802.9850000000042,
          -3002.969999999979,
          -12999.999999999955,
          1996.9999999999145,
          5896.994000000062,
          3899.999999999917,
          -20408.945999999924,
          -14000.000000000198,
          -24303.08999999976,
          -11106.216000000099,
          -1699.9999999999638,
          -6903.120000000197,
          -18903.119999999977,
          -5703.149999999921,
          10696.850000000104,
          19796.876999999928,
          43796.90699999984,
          -9403.032999999861,
          7993.93400000017,
          3693.966999999853,
          11996.970000000107,
          -13903.009000000173,
          -4203.017999999953,
          48896.985000000095,
          -13402.958000000166,
          53197.03599999999,
          -22702.894999999968,
          7197.090000000213,
          -17902.91600000005,
          -11002.9370000002,
          -20802.93999999997,
          -32802.96999999974,
          -72600.00000000001,
          -28600.00000000017,
          -148503.24000000005,
          -61903.35999999989,
          -173800.0000000002,
          -147399.99999999997,
          264000.00000000023,
          -70803.51000000017,
          54996.399999999965,
          -68403.59399999975,
          25196.417999999827,
          -38803.570000000036,
          22096.37900000027,
          -22203.59999999996,
          49596.4179999997,
          2496.460000000313,
          -18503.546000000057,
          23796.456999999857,
          9199.999999999804,
          16100.000000000065,
          21393.00400000033,
          51993.12999999971,
          -17503.399000000132,
          -14503.413999999733,
          -8903.420000000278,
          -49103.44999999988,
          22496.519999999924,
          -94607.01999999987,
          45596.42999999987,
          30000.00000000025,
          13193.01000000013,
          -19803.450000000084,
          15696.523000000067,
          23596.549999999916,
          -83803.48900000012,
          16196.475000000071,
          8996.489999999765,
          11396.520000000195,
          81796.52000000014,
          26196.609999999913,
          -26303.35399999996,
          -32903.372000000265,
          10496.583000000179,
          -12103.411000000247,
          -4603.416999999945,
          -27903.41999999991,
          6196.549999999825,
          3996.5500000003694,
          -65803.43200000019,
          -4503.488999999947,
          -34503.569999999774,
          17399.99999999963,
          -38003.51899999977,
          82696.46299999977,
          -4603.479999999945,
          9596.529000000268,
          -37503.47400000029,
          15996.52300000015,
          -10903.47999999981,
          -35903.49200000036,
          -40299.999999999694,
          -20803.57000000015,
          19200.00000000016,
          7592.919999999807,
          -41903.53999999974,
          78196.421
         ],
         "xaxis": "x4",
         "yaxis": "y4"
        }
       ],
       "layout": {
        "annotations": [
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Balance",
          "x": 0.5,
          "xanchor": "center",
          "xref": "paper",
          "y": 1,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Drawdown",
          "x": 0.5,
          "xanchor": "center",
          "xref": "paper",
          "y": 0.7350000000000001,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Daily Pnl",
          "x": 0.5,
          "xanchor": "center",
          "xref": "paper",
          "y": 0.47000000000000003,
          "yanchor": "bottom",
          "yref": "paper"
         },
         {
          "font": {
           "size": 16
          },
          "showarrow": false,
          "text": "Pnl Distribution",
          "x": 0.5,
          "xanchor": "center",
          "xref": "paper",
          "y": 0.20500000000000002,
          "yanchor": "bottom",
          "yref": "paper"
         }
        ],
        "height": 1000,
        "template": {
         "data": {
          "bar": [
           {
            "error_x": {
             "color": "#2a3f5f"
            },
            "error_y": {
             "color": "#2a3f5f"
            },
            "marker": {
             "line": {
              "color": "#E5ECF6",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "bar"
           }
          ],
          "barpolar": [
           {
            "marker": {
             "line": {
              "color": "#E5ECF6",
              "width": 0.5
             },
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "barpolar"
           }
          ],
          "carpet": [
           {
            "aaxis": {
             "endlinecolor": "#2a3f5f",
             "gridcolor": "white",
             "linecolor": "white",
             "minorgridcolor": "white",
             "startlinecolor": "#2a3f5f"
            },
            "baxis": {
             "endlinecolor": "#2a3f5f",
             "gridcolor": "white",
             "linecolor": "white",
             "minorgridcolor": "white",
             "startlinecolor": "#2a3f5f"
            },
            "type": "carpet"
           }
          ],
          "choropleth": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "choropleth"
           }
          ],
          "contour": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "contour"
           }
          ],
          "contourcarpet": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "contourcarpet"
           }
          ],
          "heatmap": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "heatmap"
           }
          ],
          "heatmapgl": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "heatmapgl"
           }
          ],
          "histogram": [
           {
            "marker": {
             "pattern": {
              "fillmode": "overlay",
              "size": 10,
              "solidity": 0.2
             }
            },
            "type": "histogram"
           }
          ],
          "histogram2d": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "histogram2d"
           }
          ],
          "histogram2dcontour": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "histogram2dcontour"
           }
          ],
          "mesh3d": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "type": "mesh3d"
           }
          ],
          "parcoords": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "parcoords"
           }
          ],
          "pie": [
           {
            "automargin": true,
            "type": "pie"
           }
          ],
          "scatter": [
           {
            "fillpattern": {
             "fillmode": "overlay",
             "size": 10,
             "solidity": 0.2
            },
            "type": "scatter"
           }
          ],
          "scatter3d": [
           {
            "line": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatter3d"
           }
          ],
          "scattercarpet": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattercarpet"
           }
          ],
          "scattergeo": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattergeo"
           }
          ],
          "scattergl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattergl"
           }
          ],
          "scattermapbox": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scattermapbox"
           }
          ],
          "scatterpolar": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterpolar"
           }
          ],
          "scatterpolargl": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterpolargl"
           }
          ],
          "scatterternary": [
           {
            "marker": {
             "colorbar": {
              "outlinewidth": 0,
              "ticks": ""
             }
            },
            "type": "scatterternary"
           }
          ],
          "surface": [
           {
            "colorbar": {
             "outlinewidth": 0,
             "ticks": ""
            },
            "colorscale": [
             [
              0,
              "#0d0887"
             ],
             [
              0.1111111111111111,
              "#46039f"
             ],
             [
              0.2222222222222222,
              "#7201a8"
             ],
             [
              0.3333333333333333,
              "#9c179e"
             ],
             [
              0.4444444444444444,
              "#bd3786"
             ],
             [
              0.5555555555555556,
              "#d8576b"
             ],
             [
              0.6666666666666666,
              "#ed7953"
             ],
             [
              0.7777777777777778,
              "#fb9f3a"
             ],
             [
              0.8888888888888888,
              "#fdca26"
             ],
             [
              1,
              "#f0f921"
             ]
            ],
            "type": "surface"
           }
          ],
          "table": [
           {
            "cells": {
             "fill": {
              "color": "#EBF0F8"
             },
             "line": {
              "color": "white"
             }
            },
            "header": {
             "fill": {
              "color": "#C8D4E3"
             },
             "line": {
              "color": "white"
             }
            },
            "type": "table"
           }
          ]
         },
         "layout": {
          "annotationdefaults": {
           "arrowcolor": "#2a3f5f",
           "arrowhead": 0,
           "arrowwidth": 1
          },
          "autotypenumbers": "strict",
          "coloraxis": {
           "colorbar": {
            "outlinewidth": 0,
            "ticks": ""
           }
          },
          "colorscale": {
           "diverging": [
            [
             0,
             "#8e0152"
            ],
            [
             0.1,
             "#c51b7d"
            ],
            [
             0.2,
             "#de77ae"
            ],
            [
             0.3,
             "#f1b6da"
            ],
            [
             0.4,
             "#fde0ef"
            ],
            [
             0.5,
             "#f7f7f7"
            ],
            [
             0.6,
             "#e6f5d0"
            ],
            [
             0.7,
             "#b8e186"
            ],
            [
             0.8,
             "#7fbc41"
            ],
            [
             0.9,
             "#4d9221"
            ],
            [
             1,
             "#276419"
            ]
           ],
           "sequential": [
            [
             0,
             "#0d0887"
            ],
            [
             0.1111111111111111,
             "#46039f"
            ],
            [
             0.2222222222222222,
             "#7201a8"
            ],
            [
             0.3333333333333333,
             "#9c179e"
            ],
            [
             0.4444444444444444,
             "#bd3786"
            ],
            [
             0.5555555555555556,
             "#d8576b"
            ],
            [
             0.6666666666666666,
             "#ed7953"
            ],
            [
             0.7777777777777778,
             "#fb9f3a"
            ],
            [
             0.8888888888888888,
             "#fdca26"
            ],
            [
             1,
             "#f0f921"
            ]
           ],
           "sequentialminus": [
            [
             0,
             "#0d0887"
            ],
            [
             0.1111111111111111,
             "#46039f"
            ],
            [
             0.2222222222222222,
             "#7201a8"
            ],
            [
             0.3333333333333333,
             "#9c179e"
            ],
            [
             0.4444444444444444,
             "#bd3786"
            ],
            [
             0.5555555555555556,
             "#d8576b"
            ],
            [
             0.6666666666666666,
             "#ed7953"
            ],
            [
             0.7777777777777778,
             "#fb9f3a"
            ],
            [
             0.8888888888888888,
             "#fdca26"
            ],
            [
             1,
             "#f0f921"
            ]
           ]
          },
          "colorway": [
           "#636efa",
           "#EF553B",
           "#00cc96",
           "#ab63fa",
           "#FFA15A",
           "#19d3f3",
           "#FF6692",
           "#B6E880",
           "#FF97FF",
           "#FECB52"
          ],
          "font": {
           "color": "#2a3f5f"
          },
          "geo": {
           "bgcolor": "white",
           "lakecolor": "white",
           "landcolor": "#E5ECF6",
           "showlakes": true,
           "showland": true,
           "subunitcolor": "white"
          },
          "hoverlabel": {
           "align": "left"
          },
          "hovermode": "closest",
          "mapbox": {
           "style": "light"
          },
          "paper_bgcolor": "white",
          "plot_bgcolor": "#E5ECF6",
          "polar": {
           "angularaxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           },
           "bgcolor": "#E5ECF6",
           "radialaxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           }
          },
          "scene": {
           "xaxis": {
            "backgroundcolor": "#E5ECF6",
            "gridcolor": "white",
            "gridwidth": 2,
            "linecolor": "white",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "white"
           },
           "yaxis": {
            "backgroundcolor": "#E5ECF6",
            "gridcolor": "white",
            "gridwidth": 2,
            "linecolor": "white",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "white"
           },
           "zaxis": {
            "backgroundcolor": "#E5ECF6",
            "gridcolor": "white",
            "gridwidth": 2,
            "linecolor": "white",
            "showbackground": true,
            "ticks": "",
            "zerolinecolor": "white"
           }
          },
          "shapedefaults": {
           "line": {
            "color": "#2a3f5f"
           }
          },
          "ternary": {
           "aaxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           },
           "baxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           },
           "bgcolor": "#E5ECF6",
           "caxis": {
            "gridcolor": "white",
            "linecolor": "white",
            "ticks": ""
           }
          },
          "title": {
           "x": 0.05
          },
          "xaxis": {
           "automargin": true,
           "gridcolor": "white",
           "linecolor": "white",
           "ticks": "",
           "title": {
            "standoff": 15
           },
           "zerolinecolor": "white",
           "zerolinewidth": 2
          },
          "yaxis": {
           "automargin": true,
           "gridcolor": "white",
           "linecolor": "white",
           "ticks": "",
           "title": {
            "standoff": 15
           },
           "zerolinecolor": "white",
           "zerolinewidth": 2
          }
         }
        },
        "width": 1000,
        "xaxis": {
         "anchor": "y",
         "domain": [
          0,
          1
         ]
        },
        "xaxis2": {
         "anchor": "y2",
         "domain": [
          0,
          1
         ]
        },
        "xaxis3": {
         "anchor": "y3",
         "domain": [
          0,
          1
         ]
        },
        "xaxis4": {
         "anchor": "y4",
         "domain": [
          0,
          1
         ]
        },
        "yaxis": {
         "anchor": "x",
         "domain": [
          0.7949999999999999,
          1
         ]
        },
        "yaxis2": {
         "anchor": "x2",
         "domain": [
          0.53,
          0.7350000000000001
         ]
        },
        "yaxis3": {
         "anchor": "x3",
         "domain": [
          0.265,
          0.47000000000000003
         ]
        },
        "yaxis4": {
         "anchor": "x4",
         "domain": [
          0,
          0.20500000000000002
         ]
        }
       }
      }
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "engine.add_strategy(KLinePatternStrategy, {})\n",
    "engine.run_backtesting()\n",
    "df = engine.calculate_result()\n",
    "engine.calculate_statistics()\n",
    "engine.show_chart()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(True, '范围参数添加成功，数量10')"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "setting = OptimizationSetting()\n",
    "setting.set_target(\"sharpe_ratio\")\n",
    "setting.add_parameter(\"fixed_size\", 1, 10, 1)\n",
    "\n",
    "# engine.run_ga_optimization(setting)\n",
    "# engine.run_bf_optimization(setting)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "vnpy",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
